package ysq.xyg.sys.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.base.service.impl.BaseServiceImpl;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.sys.dao.SysLogLoginDao;
import ysq.xyg.sys.model.po.SysLogLogin;
import ysq.xyg.sys.model.po.SysUser;
import ysq.xyg.sys.model.vo.SysLogLoginVo;
import ysq.xyg.sys.service.SysLogLoginService;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;


/**
 * 系统管理-登录日志service实现
 *
 * @author shengQiang yu
 * @date 2019-3-28 16:42:01
 */
@Service("sysLogLoginService")
public class SysLogLoginServiceImpl extends BaseServiceImpl<SysLogLogin> implements SysLogLoginService {

    @Resource
    private SysLogLoginDao sysLogLoginDao;

    private SysLogLogin sysLogLogin;

    @Autowired
    public void setBaseDao(SysLogLoginDao sysLogLoginDao) {
        this.baseDao = sysLogLoginDao;
    }


    /**
     * 分页查询
     *
     * @param sysLogLoginVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @return ReturnEntity 对象
     * @author shengQiang yu
     * @date 2019-3-28 16:42:01
     */
    public ReturnEntity page(SysLogLoginVo sysLogLoginVo, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        PageHelper.orderBy(" create_time desc");
        List<SysLogLogin> list = acceptList(sysLogLoginVo);
        PageInfo<SysLogLogin> page=new PageInfo<SysLogLogin>(list);
        return new ReturnEntity(page.getList(),page.getTotal(),page.isHasNextPage());
    }

    /**
     * 获取集合
     *
     * @param sysLogLoginVo 对象
     * @return List<BaseDict> BaseDict集合
     * @author shengQiang yu
     * @date 2019-3-28 16:42:01
     */
    public List<SysLogLogin> acceptList(SysLogLoginVo sysLogLoginVo){
        Example example = new Example(SysLogLogin.class);
        Example.Criteria criteria = example.createCriteria();
        if(StringUtil.isNotEmpty(sysLogLoginVo.getOperatorType())){
            criteria.andEqualTo("operatorType",sysLogLoginVo.getOperatorType());
        }
        if(StringUtil.isNotEmpty(sysLogLoginVo.getOperStatus())){
            criteria.andEqualTo("operStatus",sysLogLoginVo.getOperStatus());
        }
        if(StringUtil.isNotEmpty(sysLogLoginVo.getLoginName())){
            criteria.andLike("loginName","%" + sysLogLoginVo.getLoginName()+"%");
        }
        if(StringUtil.isNotEmpty(sysLogLoginVo.getOperIp())){
            criteria.andLike("operIp","%" + sysLogLoginVo.getOperIp()+"%");
        }
        example.setOrderByClause(" create_time desc");
        return sysLogLoginDao.selectByExample(example);
    }
}
